package com.cellulam.framework.core.exceptions;

import com.cellulam.framework.core.model.DataResult;
import lombok.Getter;

@Getter
public class BusinessException extends RuntimeException {
    private int code;

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BusinessException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public BusinessException(ErrorStatus errorStatus) {
        this(errorStatus.getStatus(), errorStatus.getMessage());
    }

    public BusinessException(ErrorStatus errorStatus, Throwable cause) {
        this(errorStatus.getStatus(), errorStatus.getMessage(), cause);
    }

    public DataResult toDataResult() {
        return DataResult.fail(this.code, this.getMessage());
    }
}
